package com.leijie.zerocopy;

import java.io.FileInputStream;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * @author LeiJie
 * @time 2020-5-15 17:35
 * @desc TODO
 */
public class NewIOClient {

    public static void main(String[] args) throws Exception{
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("localhost",8899));
        socketChannel.configureBlocking(true);

        String filePath = "E:\\BaiduNetdiskDownload\\808server-mysql.rar";
        FileChannel fileChannel = new FileInputStream(filePath).getChannel();
        long fileSize = fileChannel.size();
        System.out.println("fileSize:"+fileSize);
        long startTime = System.currentTimeMillis();
        long size = fileChannel.transferTo(0,fileSize,socketChannel);
        System.out.println("发送总字节数："+size+",耗时："+(System.currentTimeMillis()-startTime));
        fileChannel.close();
        socketChannel.close();
        //69781494
        //8388608
    }
}
